package shape;


import com.itextpdf.text.BaseColor;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfSpotColor;
import com.itextpdf.text.pdf.PdfWriter;
import constant.Constant;
import entry.Position;



import java.util.List;


public class LineShape implements Shape {

    private List<Position> listPosition;
    private float strokeWidth;
    private PdfSpotColor color;

    public LineShape() {
    }

    public LineShape(List<Position> listPosition, float strokeWidth, PdfSpotColor color) {
        this.listPosition = listPosition;
        this.strokeWidth = strokeWidth;
        this.color = color;
    }

    public List<Position> getListPosition() {
        return listPosition;
    }

    public void setListPosition(List<Position> listPosition) {
        this.listPosition = listPosition;
    }

    public float getStrokeWidth() {
        return strokeWidth;
    }

    public void setStrokeWidth(float strokeWidth) {
        this.strokeWidth = strokeWidth;
    }

    public PdfSpotColor getColor() {
        return color;
    }

    public void setColor(PdfSpotColor color) {
        this.color = color;
    }

    @Override
    public void draw(PdfContentByte cb) {
        if (listPosition!=null&&listPosition.size()>1) {
            cb.setLineWidth(strokeWidth*Constant.pt);
            cb.setColorStroke(color,1);
            int k=0;
            for(Position position:listPosition){
                if(k==0){
                    cb.moveTo(position.getX() * Constant.pt,position.getY() * Constant.pt );
                }else{
                    cb.lineTo(position.getX() * Constant.pt,position.getY() * Constant.pt );
                }
                k++;
            }
            cb.closePathStroke();

        }
    }

    @Override
    public void draw(PdfContentByte cb, PdfWriter writer) throws Exception {

    }
}
